/**
 * [OElove Webapp] (C)2010-2099 oelove.com Inc.
 * Email: service@phpcoo.com，phpcoo@qq.com
 * This is not a freeware, use is subject to license terms
 * $ LastTime 2017.02.08 Update by CL $
*/
$(function(){

	//同意
	$(document).on("click", "[f='but_yueta_agree']", function(){
		$_id = $(this).attr("data-id");
		$_url = _OE_FILE+"&c=yuetabm&a=agree&id="+$_id;
		oeAjaxConfirmBox($_url, "确定同意赴约吗？", function(){
			window.location.reload();
		});
	});
	//拒绝
	$(document).on("click", "[f='but_yueta_refuse']", function(){
		$_id = $(this).attr("data-id");
		$_url = _OE_FILE+"&c=yuetabm&a=refuse&id="+$_id;
		oeAjaxConfirmBox($_url, "确定拒绝赴约吗？", function(){
			window.location.reload();
		});
	});

	//查看联系方式
	$(document).on("click", "[f='but_view_contact']", function(){
		$_id = $(this).attr("data-id");
		$width = $(this).attr("data-width");
		if (typeof($width) == "undefined") {
			$width = 500;
		}
		$height = $(this).attr("data-height");
		if (typeof($height) == "undefined") {
			$height = 380;
		}
		$_url = _ROOT_PATH+"index.php?m=user&c=yuetabm&a=viewcontact&id="+$_id+"&r="+get_rndnum(8);
		oeShadeBox("pop_yuetabm_viewcontact", "ajax", $_url, $width, $height);
	});

	//显示、隐藏操作
	$(document).on("click", "[f='but_drophand']", function(){
		if ($(this).parent().find("div").css("display") == "block") {
			$(this).parent().find("div").slideUp(100);
		}
		else {
			$(this).parent().find("div").slideDown(100);
		}
	});

	//领取提示
	$(document).on("click", "[f='but_redbagtips']", function(){
		ToastShow("只有同意了应约才可以领取见面礼哦！");
	});

	//申请领取
	$(document).on("click", "[f='but_app_redbag']", function(){
		$_id = $(this).attr("data-id");
		$width = $(this).attr("data-width");
		if (typeof($width) == "undefined") {
			$width = 540;
		}
		$height = $(this).attr("data-height");
		if (typeof($height) == "undefined") {
			$height = 520;
		}
		$_url = _ROOT_PATH+"index.php?m=user&c=yuetabm&a=keep&id="+$_id+"&r="+get_rndnum(8);
		oeShadeBox("pop_app_yuetabm_redbag", "ajax", $_url, $width, $height);
	});
	//保存领取
	$(document).on("click", "[f='but_get_keep']", function(){
		$_id = $(this).attr("data-id");
		$keeptime = $("#keeptime").val();
		$keepscore = $("#keepscore").val();
		$keepdes = $("#keepdes").val();
		if ($keeptime.length == 0) {
			ToastShow("请填写约会日期");
			return false;
		}
		if ($keepscore.length == 0) {
			ToastShow("请打印象评分");
			return false;
		}
		if ($keepdes.length == 0) {
			ToastShow("请填写约会描述");
			return false;
		}
		
		$.ajax({
			type: "POST",
			url: _ROOT_PATH + "index.php?m=user&c=yuetabm",
			cache: false,
			data: {
					a:"savekeep", id:$_id, keeptime:$keeptime, keepscore:$keepscore, 
					keepdes:$keepdes, datatype:"json", r:get_rndnum(8)
			},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					_closeShadeBox("pop_app_yuetabm_redbag", function(){
						ToastShow("申请成功，请等待审核！");
						setTimeout(function(){
							window.location.reload();
						}, 300);
					});
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("提交失败");
					}
				}
				$("#ajax_loading").remove();
			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
			}
		});

	});

	//打分
	$(document).on("click", "[f='but_mark_score']", function(){
		$("._score_list span").removeClass("current");
		$val = parseInt($(this).attr("data-val"));
		for ($i=1; $i<($val+1); $i++) {
			$("#_score_"+$i).addClass("current");
		}
		$("#keepscore").val($val);
	});

	
});
